/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>

#import "RAChapterListController.h"
#import "HKLTabBarController.h"

@interface AppDelegate() <KAAdSplashDelegate>
@end

@implementation AppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
  [[KATracking sharedInstance] initWithAppId:@"qvxznKmYWkGEedJl" channel:@"jOz8EQ"];
  
  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  HKLTabBarController *tabBarController = [[HKLTabBarController alloc]init];
  self.window.rootViewController = tabBarController;
  [self.window makeKeyAndVisible];
  
  [self addAd];
  
  return YES;
}

- (void)addAd {
  //  // 设置你工程的启动页使用的是:LaunchImage 还是 LaunchScreen.storyboard(不设置默认:LaunchImage)
  //  [XHLaunchAd setLaunchSourceType:SourceTypeLaunchImage];
  //
  //  //配置广告数据
  //  XHLaunchImageAdConfiguration *imageAdconfiguration = [XHLaunchImageAdConfiguration defaultConfiguration];
  //  //广告图片URLString/或本地图片名(.jpg/.gif请带上后缀)
  //  imageAdconfiguration.imageNameOrURLString = @"http://e.hiphotos.baidu.com/image/pic/item/b8014a90f603738d952a8450be1bb051f819ec64.jpg";
  //  //广告点击打开页面参数(openModel可为NSString,模型,字典等任意类型)
  ////  imageAdconfiguration.openModel = @"http://www.baidu.com";
  //  //显示图片开屏广告
  //  [XHLaunchAd imageAdWithImageAdConfiguration:imageAdconfiguration delegate:self];
  
  
  
  //  //1.因为数据请求是异步的,请在数据请求前,调用下面方法配置数据等待时间.
  //  //2.设为3即表示:启动页将停留3s等待服务器返回广告数据,3s内等到广告数据,将正常显示广告,否则将不显示
  //  //3.数据获取成功,配置广告数据后,自动结束等待,显示广告
  //  //注意:请求广告数据前,必须设置此属性,否则会先进入window的的根控制器
  //  [XHLaunchAd setWaitDataDuration:3];
  //
  //  //广告数据请求
  //  [Network getLaunchAdImageDataSuccess:^(NSDictionary * response) {
  //
  //    NSLog(@"广告数据 = %@",response);
  //
  //    //广告数据转模型
  //    LaunchAdModel *model = [[LaunchAdModel alloc] initWithDict:response[@"data"]];
  //    //配置广告数据
  //    XHLaunchImageAdConfiguration *imageAdconfiguration = [XHLaunchImageAdConfiguration defaultConfiguration];
  //    //广告图片URLString/或本地图片名(.jpg/.gif请带上后缀)
  //    imageAdconfiguration.imageNameOrURLString = model.content;
  //    //广告点击打开页面参数(openModel可为NSString,模型,字典等任意类型)
  //    imageAdconfiguration.openModel = model.openUrl;
  //    //显示开屏广告
  //    [XHLaunchAd imageAdWithImageAdConfiguration:imageAdconfiguration delegate:self];
  //
  //  } failure:^(NSError *error) {
  //  }];
  
  KAAdSplash *splash = [[KAAdSplash alloc] initWithSlot:@"MBAlJryR" delegate:self];
  [splash loadAndPresentWithViewController:self.window.rootViewController];
  
}

#pragma mark - KAAdSplashDelegate
// Ad is successfully presented
- (void) splashAdPresentDidSuccess:(nonnull KAAdSplash *)splashAd {
  NSLog(@"");
}

// Ad present has failed
- (void) splashAdPresentDidFail:(nonnull NSString *)splashAdSlot
                      withError:(nonnull NSError *)error {
  NSLog(@"");
}

// Ad has been clicked
- (void) splashAdDidClick:(KAAdSplash *)splashAd {
  NSLog(@"");
}

// Ad view has been dismissed from screen
- (void) splashAdDidDismiss:(KAAdSplash *)splashAd {
  NSLog(@"");
}

@end
